﻿<%@ Page  MasterPageFile="~/templates/template.Master" Language="C#" AutoEventWireup="true" CodeBehind="oportunidad.aspx.cs" Inherits="GesWork.ventas.oportunidad" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


    <asp:content ID="df" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
      
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" 
            DataSourceID="dsOportunidad" ForeColor="#333333"  
            Width="690px" AllowPaging="True"  >
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#b3b3b3"  /><EditRowStyle  BackColor="#b3b3b3"  ForeColor="White" />
            <EditItemTemplate>
            <div class="recuadro">
                <!-- <b>ID:</b> -->
                <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' Visible="false"/>
                 
                 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Fecha de inicio:</b>
                <asp:TextBox ID="StartDateTextBox" runat="server" 
                    Text='<%# Bind("StartDate", "{0:dd/MM/yyyy}") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                <br />
                <b>Asunto:</b>
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                
                <b>Cliente:</b>
                         <asp:DropDownList ID="CmbIDToUserIns" runat="server" Text='<%# Bind("IdCustomer") %>'
                            DataSourceID="dsContactIns" DataTextField="Name" DataValueField="ID"  
                                >
                            </asp:DropDownList>
                         
                         <br /><br />
                         <div class="separador"></div>   
                        <br />
                       
                        <asp:SqlDataSource ID="dsContactIns" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                            SelectCommand="SELECT [Name]+' '+[FirstName]+' '+[LastName] as Name, [ID] FROM [Contact]  ORDER BY FirstName"></asp:SqlDataSource>
                       
               
               
                <b>Valoracion:</b>
                <asp:DropDownList ID="IdRattingTextBox" runat="server" 
                    Text='<%# Bind("IdRatting") %>' >
                     <asp:ListItem Text="Fria" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Templada" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Caliente" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                    
                    
                <br />
                 <b>Responsable:</b>
                <asp:Label ID="IdOwnerUserLabel" runat="server" 
                    Text='<%# Bind("IdOwnerUser") %>' />
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Fase de venta:</b>
                
                    <asp:DropDownList ID="IdSaleStageCmb" runat="server"  Text='<%# Bind("IdSaleStage") %>' 
                    DataSourceID="dsFaseVenta" DataTextField="Description" DataValueField="ID">
                    </asp:DropDownList>
                <asp:SqlDataSource ID="dsFaseVenta" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [SaleStage]">
                </asp:SqlDataSource>
                <br />
                <b>Prioridad:</b>
                
                    <asp:DropDownList ID="IdPriorityCmb" runat="server"  Text='<%# Bind("IdPriority") %>' 
                    DataSourceID="dsPriority" DataTextField="Description" DataValueField="ID">
                    </asp:DropDownList>
                     <asp:SqlDataSource ID="dsPriority" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [ActivityPriority]">
                </asp:SqlDataSource>
                <br />
                <b>Estado:</b>
                <asp:DropDownList ID="IdStateCombo" runat="server" 
                    Text='<%# Bind("IdState") %>' >
                     <asp:ListItem Text="Abierta" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Ganada" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Perdida" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                
               
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Metodo de estimacion de ingresos:</b>
                
                    
                    <asp:DropDownList ID="RE_IdRevenueInputMethodTextBox" runat="server" 
                    Text='<%# Bind("RE_IdRevenueInputMethod") %>' >
                     <asp:ListItem Text="Automatico" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Manual" Value="1"></asp:ListItem>
                   
                    </asp:DropDownList>
                
                    
                <br />
                <b>Ingresos estimados:</b>
                <asp:TextBox ID="RE_RevenueTextBox" runat="server" 
                    Text='<%# Bind("RE_Revenue") %>' />
                <br />
                <b>Probabilidad:</b>
                <asp:TextBox ID="RE_ProbabilityTextBox" runat="server" 
                    Text='<%# Bind("RE_Probability") %>' />
                <br />
                <b>Fecha de cierre de estimacion:</b>
                <asp:TextBox ID="RE_DueDateTextBox" runat="server" 
                    Text='<%# Bind("RE_DueDate", "{0:dd/MM/yyyy}") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="RE_DueDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                <br />
                <b>Descripcion:</b>
                <asp:TextBox ID="DescriptionTextBox" runat="server" 
                    Text='<%# Bind("Description") %>' />
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Ingresos reales:</b>
                <asp:TextBox ID="CO_RevenueTextBox" runat="server" 
                    Text='<%# Bind("CO_Revenue") %>' />
                <br />
                <b>Fecha de cierre:</b>
                <asp:TextBox ID="CO_ClosedDateTextBox" runat="server" 
                    Text='<%# Bind("CO_ClosedDate", "{0:dd/MM/yyyy}") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="CO_ClosedDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
               
                
                 
<asp:ImageButton ID="UpdateButton" runat="server"  ImageUrl="~/images/btnGuardar.png"  CssClass="botones" CausesValidation="True" 
                    CommandName="Update" Text="Actualizar" />
               
<asp:ImageButton ID="UpdateCancelButton" runat="server"  ImageUrl="~/images/btnCancelar.png"  CssClass="botones" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancelar" />
     
                  </div>
            </EditItemTemplate>
            <InsertItemTemplate>
            <div class="recuadro">
                <b>Fecha de Inicio:</b>
                <asp:TextBox ID="StartDateTextBox" runat="server" 
                    Text='<%# Bind("StartDate") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="StartDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                <br />
                <b>Asunto:</b>
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                <b>Cliente:</b>
                
                     <asp:DropDownList ID="CmbIDToUserIns" runat="server"  Text='<%# Bind("IdCustomer") %>'
                        DataSourceID="dsContactIns" DataTextField="Name" DataValueField="ID"  
                            >
                        </asp:DropDownList>
                     
                     <br /><br />
                     <div class="separador"></div>   
                    <br />
                   
                    <asp:SqlDataSource ID="dsContactIns" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                        SelectCommand="SELECT [Name]+' '+[FirstName]+' '+[LastName] as Name, [ID] FROM [Contact] ORDER BY FirstName"></asp:SqlDataSource>
                        
                <br />
                
                <b>Valoracion:</b>
                
                <asp:DropDownList ID="DropDownList1" runat="server" 
                    Text='<%# Bind("IdRatting") %>' >
                     <asp:ListItem Text="Fria" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Templada" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Caliente" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                    
                <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                 <b>Responsable:</b>
                <asp:Label ID="IdOwnerUserLabel" runat="server" 
                    Text='<%# Bind("IdOwnerUser") %>' />
                
                
                 <br />
                 
                 <b>Fase de venta:</b>
                
                    <asp:DropDownList ID="IdSaleStageCmb" runat="server"  Text='<%# Bind("IdSaleStage") %>' 
                    DataSourceID="dsFaseVenta" DataTextField="Description" DataValueField="ID">
                    </asp:DropDownList>
                <asp:SqlDataSource ID="dsFaseVenta" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [SaleStage]">
                </asp:SqlDataSource>
                <br />
                <b>Prioridad:</b>
                
                    <asp:DropDownList ID="IdPriorityCmb" runat="server"  Text='<%# Bind("IdPriority") %>' 
                    DataSourceID="dsPriority" DataTextField="Description" DataValueField="ID">
                    </asp:DropDownList>
                     <asp:SqlDataSource ID="dsPriority" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [ActivityPriority]">
                </asp:SqlDataSource>
                <br />
                <b>Estado:</b>
              
                
                 <asp:DropDownList ID="DropDownList2" runat="server" 
                    Text='<%# Bind("IdState") %>' >
                     <asp:ListItem Text="Abierta" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Ganada" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Perdida" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                
                <b>Metodo de estimacion de ingresos:</b>
                
                    
                      <asp:DropDownList ID="RE_IdRevenueInputMethodCombo" runat="server" 
                    Text='<%# Bind("RE_IdRevenueInputMethod") %>' >
                     <asp:ListItem Text="Automatico" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Manual" Value="1"></asp:ListItem>
                   
                    </asp:DropDownList>
                <br />
                <b>Ingresos estimados:</b>
                <asp:TextBox ID="RE_RevenueTextBox" runat="server" 
                    Text='<%# Bind("RE_Revenue") %>' />
                <br />
                <b>Probabilidad:</b>
                <asp:TextBox ID="RE_ProbabilityTextBox" runat="server" 
                    Text='<%# Bind("RE_Probability") %>' />
                <br />
                <b>Fecha de cierre de estimacion:</b>
                <asp:TextBox ID="RE_DueDateTextBox" runat="server" 
                    Text='<%# Bind("RE_DueDate") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="RE_DueDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                <br />
                <b>Descripcion:</b>
                <asp:TextBox ID="DescriptionTextBox" runat="server" 
                    Text='<%# Bind("Description") %>' />
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                
                <b>Ingresos Reales:</b>
                <asp:TextBox ID="CO_RevenueTextBox" runat="server" 
                    Text='<%# Bind("CO_Revenue") %>' />
                <br />
                <b>Fecha de Cierre:</b>
                <asp:TextBox ID="CO_ClosedDateTextBox" runat="server" 
                    Text='<%# Bind("CO_ClosedDate") %>' />
                    <cc1:CalendarExtender ID="CalendarExtender5" runat="server" TargetControlID="CO_ClosedDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
                
                 <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                
      
<asp:ImageButton ID="InsertButton" runat="server"  ImageUrl="~/images/btnGuardar.png"  CssClass="botones" CausesValidation="True" 
                    CommandName="Insert" Text="Insertar" />
               
<asp:ImageButton ID="InsertCancelButton" runat="server"  ImageUrl="~/images/btnCancelar.png"  CssClass="botones" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancelar" />           </div>
            </InsertItemTemplate>
            <ItemTemplate>
             <div class="separador"></div> 
               <!--  <br />
                <b>ID:</b> -->
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' Visible="false"/>
                
                
                 <br />
                 
                  
                <b>Asunto:</b>
                <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("name") %>' />
                <br />
                
                <b>Fecha de inicio:</b>
                <asp:Label ID="StartDateLabel" runat="server" Text='<%# Eval("StartDate", "{0:dd/MM/yyyy}") %>' />
                <br />
               
                
                <b>Cliente:</b>
                <asp:Label ID="IdCustomerLabel" runat="server" 
                    Text='<%# Eval("contactName") %>' />
                <br />
                
                <b>Valoracion:</b>
                <asp:Label ID="IdRattingLabel" runat="server" Text='<%# asignarValoracion(Eval("IdRatting").ToString()) %>' />
                <br />
                <b>Responsable:</b>
                <asp:Label ID="IdOwnerUserLabel" runat="server" 
                    Text='<%# Eval("IdOwnerUser") %>' />
                
                
                <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Fase de Venta:</b>
                <asp:Label ID="IdSaleStageLabel" runat="server" 
                    Text='<%# Eval("SaleStage") %>' />
                <br />
                <b>Prioridad:</b>
                <asp:Label ID="IdPriorityLabel" runat="server" 
                    Text='<%# Eval("Priority") %>' />
                <br />
                <b>Estado:</b>
                <asp:Label ID="IdStateLabel" runat="server" Text='<%# asignarEstado(Eval("IdState").ToString()) %>' />
                
                <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                
                <b>Metodo estimacion de Ingresos:</b>
                <asp:Label ID="RE_IdRevenueInputMethodLabel" runat="server" 
                    Text='<%# asignarMetEst(Eval("RE_IdRevenueInputMethod").ToString()) %>' />
                <br />
                <b>Ingresos estimados:</b>
                <asp:Label ID="RE_RevenueLabel" runat="server" 
                    Text='<%# Eval("RE_Revenue") %>' />
                <br />
                <b>Probabilidad:</b>
                <asp:Label ID="RE_ProbabilityLabel" runat="server" 
                    Text='<%# Eval("RE_Probability") %>' />
                <br />
                <b>Fecha cierre estimacion:</b>
                <asp:Label ID="RE_DueDateLabel" runat="server" 
                    Text='<%# Eval("RE_DueDate", "{0:dd/MM/yyyy}") %>' />
                <br />
                <b>Description:</b>
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
                
                <br />
                <br /> 
                 <div class="separador"></div> 
                 <br />
                 
                <b>Ingresos Reales:</b>
                <asp:Label ID="CO_RevenueLabel" runat="server" 
                    Text='<%# Eval("CO_Revenue") %>' />
                <br />
                <b>Fecha cierre:</b>
                <asp:Label ID="CO_ClosedDateLabel" runat="server" 
                    Text='<%# Eval("CO_ClosedDate", "{0:dd/MM/yyyy}") %>' />
               
               <br /><br /> 
                 <div class="separador"></div> 
                 <br />
                
                
<asp:ImageButton ID="EditButton" runat="server"  ImageUrl="~/images/btnEditar.png"  CssClass="botones" CausesValidation="False" 
                    CommandName="Edit" Text="Editar" />

 <asp:ImageButton ID="DeleteButton" runat="server"  ImageUrl="~/images/btnEliminar.png"  CssClass="botones" CausesValidation="False" 
                    CommandName="Delete" Text="Eliminar" />
&nbsp;&nbsp; 
<asp:ImageButton ID="NewButton" runat="server"  ImageUrl="~/images/btnNuevo.png"  CssClass="botones" CausesValidation="False" CommandName="New" 
                    Text="Nuevo" />
                    
            </ItemTemplate>
        </asp:FormView>
    
        <asp:SqlDataSource ID="dsOportunidad" runat="server" 
            ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
            DeleteCommand="DELETE FROM [Oportunity] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [Oportunity] ([Name], [IdCustomer], [IdOwnerUser], [IdRatting], [IdSaleStage], [IdPriority], [IdState], [RE_IdRevenueInputMethod], [RE_Revenue], [RE_Probability], [RE_DueDate], [Description], [CO_Revenue], [CO_ClosedDate], [StartDate]) VALUES (@Name, @IdCustomer, @IdOwnerUser, @IdRatting, @IdSaleStage, @IdPriority, @IdState, @RE_IdRevenueInputMethod, @RE_Revenue, @RE_Probability, @RE_DueDate, @Description, @CO_Revenue, @CO_ClosedDate, @StartDate)" 
            SelectCommand="SELECT Oportunity.ID, Oportunity.Name , Oportunity.IdCustomer,Contact.Name+' '+Contact.FirstName+' '+Contact.LastName AS contactName,
                         Oportunity.IdOwnerUser, Oportunity.IdRatting, Oportunity.IdSaleStage,SaleStage.Description As SaleStage, 
                        Oportunity.IdPriority, ActivityPriority.Description AS priority, Oportunity.IdState, Oportunity.RE_IdRevenueInputMethod, 
                        Oportunity.RE_Revenue, Oportunity.RE_Probability, Oportunity.RE_DueDate, Oportunity.Description, 
                        Oportunity.CO_Revenue, Oportunity.CO_ClosedDate, Oportunity.StartDate 

                        FROM Oportunity, Contact,SaleStage, ActivityPriority

                        WHERE  Contact.ID = Oportunity.IdCustomer AND SaleStage.ID =Oportunity.IdSaleStage AND 
                        ActivityPriority.ID =Oportunity.IdPriority AND Oportunity.ID = @ID" 
            UpdateCommand="UPDATE [Oportunity] SET [Name] = @Name, [IdCustomer] = @IdCustomer, [IdOwnerUser] = @IdOwnerUser, [IdRatting] = @IdRatting, [IdSaleStage] = @IdSaleStage, [IdPriority] = @IdPriority, [IdState] = @IdState, [RE_IdRevenueInputMethod] = @RE_IdRevenueInputMethod, [RE_Revenue] = @RE_Revenue, [RE_Probability] = @RE_Probability, [RE_DueDate] = @RE_DueDate, [Description] = @Description, [CO_Revenue] = @CO_Revenue, [CO_ClosedDate] = @CO_ClosedDate, [StartDate] = @StartDate WHERE [ID] = @ID">
            <SelectParameters>
                <asp:QueryStringParameter Name="ID" QueryStringField="id" Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="IdCustomer" Type="String" />
                <asp:Parameter Name="IdOwnerUser" Type="String" />
                <asp:Parameter Name="IdRatting" Type="Int32" />
                <asp:Parameter Name="IdSaleStage" Type="String" />
                <asp:Parameter Name="IdPriority" Type="Int32" />
                <asp:Parameter Name="IdState" Type="Int32" />
                <asp:Parameter Name="RE_IdRevenueInputMethod" Type="Int32" />
                <asp:Parameter Name="RE_Revenue" Type="Decimal" />
                <asp:Parameter Name="RE_Probability" Type="Decimal" />
                <asp:Parameter Name="RE_DueDate" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="CO_Revenue" Type="Decimal" />
                <asp:Parameter Name="CO_ClosedDate" Type="String"/>
                <asp:Parameter Name="StartDate" Type="String"/>
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="IdCustomer" Type="String" />
                <asp:Parameter Name="IdOwnerUser" Type="String" />
                <asp:Parameter Name="IdRatting" Type="Int32" />
                <asp:Parameter Name="IdSaleStage" Type="String" />
                <asp:Parameter Name="IdPriority" Type="Int32" />
                <asp:Parameter Name="IdState" Type="Int32" />
                <asp:Parameter Name="RE_IdRevenueInputMethod" Type="Int32" />
                <asp:Parameter Name="RE_Revenue" Type="Decimal" />
                <asp:Parameter Name="RE_Probability" Type="Decimal" />
                <asp:Parameter Name="RE_DueDate" Type="String"/>
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="CO_Revenue" Type="Decimal" />
                <asp:Parameter Name="CO_ClosedDate" Type="String"/>
                <asp:Parameter Name="StartDate" Type="String"/>
            </InsertParameters>
        </asp:SqlDataSource>
     <br />
      <br />
    </asp:content>

